package com.yyw.gulimall.elasticsearch.controller.product;

import com.yyw.common.to.productsearch.SpuInfoTo;
import com.yyw.common.utils.R;
import com.yyw.common.utils.enums.ExceptionEnum;
import com.yyw.gulimall.elasticsearch.service.product.ProductSearchService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

/**
 * @author 易煜玮
 * @ClassName ProductController.java
 * @Description 商品控制器
 * @createTime 2020年11月24日 19:04:00
 */
@RestController
@RequestMapping("/search/product")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ProductController {

    private final ProductSearchService productSearchService;

    @PostMapping("/save/skuInfo")
    public R saveSkuInfo(@RequestBody List<SpuInfoTo> spuInfoToList) {
        try {
            productSearchService.saveSkuInfo(spuInfoToList);
        } catch (IOException e) {
            e.printStackTrace();
            return R.error(ExceptionEnum.SEARCH_FEIGN_EXCEPTION.getCode(), ExceptionEnum.SEARCH_FEIGN_EXCEPTION.getMsg());
        }
        return R.ok();
    }

}
